package br.com.felix.fwt.ui.css;

import java.io.Serializable;


/**
 * Utility class to define borders around components of the user interface.
 */
public class Border implements Serializable{

	private static final long serialVersionUID = -6828744205261488823L;

	/** 
	 * The styles of the top, right, bottom, and left borders.
	 * If you omit the style, CSS default will be used.
	 * You may define 1 to 4 styles. If you define only one, it will be used at the four positions. 
	 * Consult CSS documentation for more information. 
	 * */
	public BorderStyle[] styles;
	
	/** 
	 * The widths of the top, right, bottom, and left borders.
	 * If you omit the width, CSS default will be used.
	 * You may define 1 to 4 widths. If you define only one, it will be used at the four positions. 
	 * Consult CSS documentation for more information.
	 */
	public BorderWidth[] widths;
	
	/** 
	 * The colors of the top, right, bottom, and left borders.
	 * If you omit the color, CSS default will be used.
	 * You may define 1 to 4 colors. If you define only one, it will be used at the four positions. 
	 * Consult CSS documentation for more information.
	 */
	public Color[] colors;
	
	
	/**
	 * Sets the borders' styles.
	 * 
	 * @param borderStyles the borders' styles. You may specify 0 to 4 border styles. No validation is made.
	 * 
	 * @return this instance.
	 */
	public Border borderStyle(BorderStyle ...borderStyles){
		this.styles = borderStyles;
		return this;
	}
	
	/**
	 * Sets the borders' widths.
	 * 
	 * @param borderWidths the borders' widths. You may specify 0 to 4 widths. No validation is made.
	 * 
	 * @return this instance.
	 */
	public Border borderWidth(BorderWidth ...borderWidths){
		this.widths = borderWidths;
		return this;
	}
	
	/**
	 * Sets the borders' colors.
	 * 
	 * @param colors the borders' colors. You may specify 0 to 4 widths. No validation is made.
	 * 
	 * @return the border
	 */
	public Border borderColors(Color ... colors){
		this.colors = colors;
		return this;
	}
	
	
	/**
	 * Returns the CSS definition for this Border.
	 * @return the CSS definition.
	 */
	public String toString(){
		StringBuilder strb = new StringBuilder();
		if(colors!=null){
			strb.append("border-color:");
			for(Color c:colors){
				strb.append(c.toString()).append(" ");
			}
			strb.append(";");
		}
		if(styles!=null){
			strb.append("border-style:");
			for(BorderStyle bs:styles){
				strb.append(bs.toString()).append(" ");
			}
			strb.append(";");
		}
		if(widths!=null){
			strb.append("border-width:");
			for(BorderWidth bw:widths){
				strb.append(bw.toString()).append(" ");
			}
			strb.append(";");
		}
		return strb.toString();
	}
}
